<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>用户编号：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li>
                            <label>联系方式：</label>
                            <input type="text" name="userPhone"/>
                        </li>
                        <li>
                            <label>用户类型：</label>
                            <select name="userType" th:with="type=${@dict.getType('user_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary  btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning  btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('wechat:user:edit')}]];
    var removeFlag = [[${@permission.hasPermi('wechat:user:remove')}]];
    var userTypeDatas = [[${@dict.getType('user_type')}]];
    var prefix = ctx + "wechat/user";

    $(function() {
        var options = {
            url: prefix + "/list",
            detailUrl: prefix + "/detail/{id}",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "用户",
            columns: [
                {
                    field: 'userPic',
                    title: '用户头像',
                    sortable: false,
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'userId',
                    title: '用户编号',
                    sortable: false
                },
                {
                    field: 'openid',
                    title: 'OPENID',
                    sortable: false
                },
                {
                    field: 'userName',
                    title: '用户名称',
                    sortable: false,
                    formatter: function(value, row, index) {
                        if(row.userPhone!=null&&row.userPhone!=''){
                            return value+"("+row.userPhone+")";
                        }else {
                            return value;
                        }
                    }
                },
                {
                    field: 'userType',
                    title: '用户类型',
                    sortable: false,
                    formatter: function (value, row, index) {
                        var arr = value.split(',')
                        var str = ''
                        for (var i in arr)
                            str += $.table.selectDictLabel(userTypeDatas, arr[i]) + '-'
                        return str.substring(0, str.length - 1)
                    }
                },
                {
                    field: 'userTime',
                    title: '创建时间',
                    sortable: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.userId + '\')">编辑</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function editType(id,type) {
        var title = type == 0 ? "确认设置用户为普通用户吗？" : "确认设置用户为销售吗？";
        $.modal.confirm(title, function () {
            $.operate.post(prefix + "/edit", {"userId": id, "userType": type});
        })
    }

    function edit(id) {
        $.modal.open("编辑用户", prefix + "/edit/" + id,500,600);
    }
</script>
</body>
</html>
